{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2024 Teclib' and contributors.
 # @copyright 2003-2014 by the INDEPNET Development Team.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% extends "pages/setup/general/base_form.html.twig" %}
{% import 'components/form/fields_macros.html.twig' as fields %}

{% set field_options = {
    'field_class': 'col-12 col-xxl-6 col-sm-6',
    'full_width': true,
    'rand': rand|default(random())
} %}
{% set inline_field_options = field_options|merge({
    'input_addclass': 'w-auto'
}) %}

{% block config_fields %}
<div class="hr-text">
    <i class="ti ti-shield-lock"></i>
    <span>{{ __('Password security policy') }}</span>
</div>

<div class="row ps-4">
    {{ fields.dropdownYesNo('use_password_security', config('use_password_security'), __('Password security policy validation'), inline_field_options) }}

    {{ fields.dropdownNumberField('password_min_length', config('password_min_length'), __('Password minimum length'), inline_field_options|merge({
        'min': 4,
        'max': 30
    })) }}

    {{ fields.dropdownYesNo('password_need_number', config('password_need_number'), __('Password need digit'), inline_field_options) }}

    {{ fields.dropdownYesNo('password_need_letter', config('password_need_letter'), __('Password need lowercase character'), inline_field_options) }}

    {{ fields.dropdownYesNo('password_need_caps', config('password_need_caps'), __('Password need uppercase character'), inline_field_options) }}

    {{ fields.dropdownYesNo('password_need_symbol', config('password_need_symbol'), __('Password need symbol'), inline_field_options) }}
</div>

<div class="hr-text">
    <i class="ti ti-shield-lock"></i>
    <span>{{ __('Password expiration policy') }}</span>
</div>

<div class="row ps-4">
    {{ fields.dropdownNumberField('password_expiration_delay', config('password_expiration_delay'), __('Password expiration delay (in days)'), inline_field_options|merge({
        'min': 30,
        'max': 365,
        'step': 15,
        'toadd': {'-1': __('Never')}
    })) }}

    {{ fields.dropdownNumberField('password_expiration_notice', config('password_expiration_notice'), __('Password expiration notice time (in days)'), inline_field_options|merge({
        'min': 0,
        'max': 30,
        'step': 1,
        'toadd': {'-1': __('Notification disabled')}
    })) }}

    {{ fields.dropdownNumberField('password_expiration_lock_delay', config('password_expiration_lock_delay'), __('Delay before account deactivation (in days)'), inline_field_options|merge({
        'min': 0,
        'max': 30,
        'step': 1,
        'toadd': {'-1': __('Do not deactivate')}
    })) }}

    {{ fields.dropdownTimestampField('password_init_token_delay', config('password_init_token_delay'), __('Validity period of the password initialization token'), inline_field_options|merge({
        'min': constant('DAY_TIMESTAMP'),
        'max': constant('MONTH_TIMESTAMP'),
        'step': constant('DAY_TIMESTAMP')
    })) }}

    {{ fields.dropdownArrayField(
        'non_reusable_passwords_count',
        config('non_reusable_passwords_count'),
        {
            '1': __('Last password'),
            '2': __('Last 2 passwords'),
            '3': __('Last 3 passwords'),
            '4': __('Last 4 passwords'),
            '5': __('Last 5 passwords')
        },
        __('Prevent users from reusing previous passwords'),
        inline_field_options
    ) }}
</div>

<div class="hr-text">
    <i class="ti ti-2fa"></i>
    <span>{{ __('Two-factor authentication (2FA)') }}</span>
</div>

<div class="row ps-4">
    {{ fields.dropdownYesNo('2fa_enforced', config('2fa_enforced'), __('Enforce 2FA'), inline_field_options) }}

    {{ fields.dropdownNumberField('2fa_grace_days', config('2fa_grace_days'), __('2FA grace period (in days)'), inline_field_options|merge({
        'min': 0,
        'max': 365,
    })) }}
</div>
{% endblock %}
